#include "collision.h"
#include "SDL.h"
#include <iostream>

int nvert = 4;

collision::collision(SDL_Point p1, SDL_Point p2, SDL_Point p3, SDL_Point p4){
    _pos_x.push_back(p1.x);
    _pos_x.push_back(p2.x);
    _pos_x.push_back(p3.x);
    _pos_x.push_back(p4.x);

    _pos_y.push_back(p1.y);
    _pos_y.push_back(p2.y);
    _pos_y.push_back(p3.y);
    _pos_y.push_back(p4.y);
}

bool collision::is_point_inside(SDL_Point p){

    int i, j, c = 0;
    for (i = 0, j = nvert-1; i < nvert; j = i++) {
        if ( ((_pos_y[i]>p.y) != (_pos_y[j]>p.y)) &&
            (p.x < (_pos_x[j]-_pos_x[i]) * (p.y-_pos_y[i]) / (_pos_y[j]-_pos_y[i]) + _pos_x[i]) )
                c = !c;
    }
    return c;
}
